/*
 *  DP专题
 *  最长公共子序列 力扣 1143 题
 *  线性DP
 * */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        int size1 = text1.length(), size2 = text2.length();
        vector<vector<int>> f(size1 + 1, vector<int>(size2 + 1, 0));
        for (int i = 1; i <= size1; ++i) {
            for (int j = 1; j <= size2; ++j) {
                f[i][j] = max(f[i - 1][j], f[i][j - 1]);
                if (text1[i - 1] == text2[j - 1]) {
                    f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
                }
            }
        }

        return f[size1][size2];
    }
};

int main() {

    Solution solution;

    string text1 = "abcde";
    string text2 = "ace";

    cout << solution.longestCommonSubsequence(text1, text2) << endl;

    int f[5] = {0, 3, 2, 4, 1};
    int m = *min_element(f + 1, f + 2);
    cout << m;

    return 0;
}